<?php

# -- DÉBUT NOTE DE LICENCE -------------------------------------
#
# Ce fichier fait partie de Clicpage.
#
# Copyright (c) 2010 Francois (www.clicpage.net)
# Distribué selon les termes de la licence GPL version 2.0.
# Consultez le fichier LICENCE ou
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- FIN NOTE DE LICENCE ---------------------------------------

require(dirname(__FILE__).'/_prepend.php');
require(CP_CLASS_FOLDER.'/admin/prepend.php');

try {
	
	if(empty($_POST['action']) || !isset($core->servicesAdmin[$_POST['action']])) {
		throw new cpErreur(__('Action invalide'), 'action', 301);
	}
	
	if(!$core->verifierNonce('ajax', $_POST['cpAjaxNonce'])) {
		throw new cpErreur(__('Clé de sécurité invalide'), 'nonce', 202);
	}
	
	$reponse = call_user_func($core->servicesAdmin[$_POST['action']]);
	
	if(!is_array($reponse)) {
		$reponse = array('erreur' => 0);
	}
	
	// HTTP/1.1
	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
	header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
	header('Content-Type: text/xml; charset=utf-8');
		
	// HTTP/1.0
	header("Pragma: no-cache");
	
	cpXML::arrayToXML('reponse', $reponse);
	
	
} catch (cpErreur $e) {
	
	// HTTP/1.1
	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
	header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
	header('Content-Type: text/xml; charset=utf-8');
		
	// HTTP/1.0
	header("Pragma: no-cache");
	
	cpXML::arrayToXML('reponse', array(
		'erreur' => 1,
		'message' => $e->getMessage(),
		'champ' => $e->getChamp(),
		'code' => $e->getCode()
	));
		
}

?>